#ifndef _BTNODE_H_
#define _BTNODE_H_

#include "Page.h"
#include <iostream>

using namespace std;

#define KEY unsigned
#define INTSIZE sizeof(KEY)
#define NODESIZE sizeof(BTNode *)
#define MININT 0
#define MAXINT 0xffffffff

class BTNode;

class BTNode : public Page
{
public:
	BTNode(int size, bool leaf, BufferManager * manager, int level);
	~BTNode();

	BTNode * InsertKeyIntoLeaf(KEY key);
	KEY PointQuery(KEY querykey);
	KEY RangeQuery(KEY low, KEY high);

	BTNode * FindNode(KEY key);
	int GetID() {return pageId;};

public:
	bool isLeaf;
	int maxKeyNum;
	int keyNum;
	int nodeLevel;

	BTNode * pre;
	BTNode * next;

	KEY leftFence;    // for extent
	KEY rightFence;   // for extent

	KEY * keys;
	BTNode ** pointers;
	//KEY keys[5];
	//BTNode * pointers[6];

	int FindInNONLeaf(KEY key);
	int FindInLeaf(KEY key);
	void InsertKeyIntoNONFullLeaf(KEY key);
	void InsertKeyIntoNONFullNONLeaf(KEY key, BTNode * left, BTNode * right);
	BTNode * SplitLeaf();
	BTNode * SplitNONLeaf();
	int GetSplitPoint();
	bool IsFull(){return (keyNum > maxKeyNum);};

};

#endif
